gui/macOS: Ensure file provider domain progress instances are correctly retained
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 26 Mar 2025 09:25:58 +0000 (10:25 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Wed, 26 Mar 2025 11:46:53 +0000 (11:46 +0000)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/macOS/progressobserver.m

index b52e13b26161df7b392bb5c3678693234afd10a9..f6b6aaad090398b9199db4b8f042bbac083f1c54 100644 (file)
@@ -21,6 +21,7 @@
     self = [super init];
     if (self) {
         _progress = progress;
+        [_progress retain];
         [_progress addObserver:self forKeyPath:@"totalUnitCount" options:NSKeyValueObservingOptionNew context:nil];
         [_progress addObserver:self forKeyPath:@"completedUnitCount" options:NSKeyValueObservingOptionNew context:nil];
         [_progress addObserver:self forKeyPath:@"cancelled" options:NSKeyValueObservingOptionNew context:nil];
     return self;
 }
 
+- (void)dealloc
+{
+    [_progress removeObserver:self forKeyPath:@"totalUnitCount"];
+    [_progress removeObserver:self forKeyPath:@"completedUnitCount"];
+    [_progress removeObserver:self forKeyPath:@"cancelled"];
+    [_progress removeObserver:self forKeyPath:@"paused"];
+    [_progress removeObserver:self forKeyPath:@"fileTotalCount"];
+    [_progress removeObserver:self forKeyPath:@"fileCompletedCount"];
+    [_progress release];
+    [super dealloc];
+}
+
 - (void)observeValueForKeyPath:(NSString *)keyPath
                       ofObject:(id)object
                         change:(NSDictionary *)change